library(readxl)
library(ggplot2)
library(ggiraph)
library(patchwork)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
X <-read_excel("C:/Users/Xinyue Zhan/Desktop/useful research papers/datafinal.xlsx",sheet=1)
p <- ggplot(data = X,
mapping = aes(x = dose, y = infection.rate, color=agent.strain)) +
geom_point(size = 2)+
scale_x_log10(labels = scales::comma) +
geom_line()+
theme_minimal()+ #make the data frame white
labs(title = "Probability of infection among various STEC",
x= "amount of dose",
y="Average probability",
color = "agent strain")
ggplotly(p)
p2 <- ggplot(X, aes(x=agent.strain, y=exposure, fill=agent.strain)) +
geom_bar(stat = "identity") + theme_bw() +
labs( title="number of data",
x= "agent strain",
y= "number of exposure cases") +
coord_flip() #help to solve the issue of text overlapping each other
ggplotly(p2)
x=seq(0,1,length.out=100)
a1.lower <- qbeta(0.01,7.5,8.5)
a1.upper <-qbeta(0.99,7.5,8.5)
a5.lower <-qbeta(0.05,7.5,8.5)
a5.upper <- qbeta(0.95,7.5,8.5)
a2.lower <-qbeta(0.1,7.5,8.5)
a2.upper <- qbeta(0.90,7.5,8.5)
plot(x,dbeta(x, shape1=7+1/2, shape2=8+1/2), type="l", ylab="density", xlab=expression(paste(p)), main ="Posterior distribution for E.O214-4")
abline(v=a1.lower,col=4,lty=4)# 99% of CI
abline(v=a1.upper,col=4,lty=4)# 99% of CI
abline(v=a5.lower,col=7,lty=1)# 95% of CI
abline(v=a5.upper,col=7,lty=1)# 95% of CI
abline(v=a2.lower,col=9,lty=2)# 90% of CI
abline(v=a2.upper,col=9,lty=2)# 90% of CI
legend("topleft", c("99% CI=[0.204, 0.628]", "95% CI=[0.271, 0.671]", "90% CI=[0.312, 0.628]"), cex=0.8, col=c(4,7,9), lty=c(4,1,2), bg="white")

x=seq(0,1,length.out=100)
a1.lower <- qbeta(0.01,9.5,1.5)
a1.upper <-qbeta(0.99,9.5,1.5)
a5.lower <-qbeta(0.05,9.5,1.5)
a5.upper <- qbeta(0.95,9.5,1.5)
a2.lower <-qbeta(0.1,9.5,1.5)
a2.upper <- qbeta(0.90,9.5,1.5)
plot(x,dbeta(x, shape1=9+1/2, shape2=1+1/2), type="l", ylab="density", xlab=expression(paste(p)), main ="Posterior distribution for E. O127:H6")
abline(v=a1.lower,col=4,lty=4)# 99% of CI
abline(v=a1.upper,col=4,lty=4)# 99% of CI
abline(v=a5.lower,col=7,lty=1)# 95% of CI
abline(v=a5.upper,col=7,lty=1)# 95% of CI
abline(v=a2.lower,col=9,lty=2)# 90% of CI
abline(v=a2.upper,col=9,lty=2)# 90% of CI
legend("topleft", c("99% CI=[0.0.558, 0.994]", "95% CI=[0.669, 0.982]", "90% CI=[0.725, 0.970]"), cex=0.8, col=c(4,7,9), lty=c(4,1,2), bg="white")
